2015-01-21 4 views
0

,엽차 터치 2.4.1 - 배열의 값에 geting는 JSON 문자열을 통해 전송 다음 코드는 잘 작동

는 PHP에서 보낸 //

echo("({'title':'$myTitle', 'message':'$myMessage'})"); 

// 엽차의 제어에서 아약스 응답 비트의 ,이 또한 수행하지만 그러나 개별 데이터를 얻을 질수 응용 프로그램

success: function(xhr,params) 
{   
var data = Ext.JSON.decode(xhr.responseText.trim()); 
var aTitle=data.title; //get the value of message, $myMessage 
var aMessage=data.message; 
console.log('Title:',aTitle,' - Message:',aMessage); 
}, 

터치

// PHP에서 이전과 같은 데이터의 배열, 제목과 메시지 만 많은

$data=json_encode($myArray); 
echo "({'myData':'$data'})"; 

// 엽차 터치 응용 프로그램의 컨트롤에서 아약스 응답 비트의

success: function(xhr,params) 
{   

var data = Ext.JSON.decode(xhr.responseText.trim()); 
var myArray=[]; 

Ext.Array.each(data.myData, function() 
{ 
    myArray[count]= data.myData;  

    //this will spit out all the data from array. 
    console.log('myArray contains:',myArray[count]); 

    //but i wanted to select individual bit e.g.(pseudo code ish) 
    myArray[0]=data.myData.title; 

    or 

    myArray[3]=data.myData.message; // that sort of thing 

    count=count+1;   
}); 
}, 

그 이상 이것에 실패하면 누구나 이것을 어떻게 바꿀 수 있는지 말해 줄 수 있습니다.

// 영숫자가 아닌 charecters를 없애기 myOutputString = myDataString.replace (/ \ W/g, '');

그래서 같은 exept를 제거합니다.

그럼 내가 원하는 방식으로 데이터에서 원하는 비트를 지정할 수 있습니다 (단, preffered 옵션은 아님). L.

답변

0

여기 http://docs-origin.sencha.com/touch/2.4/2.4.1-apidocs/#!/api/Ext.Array

Ext.Array에 대한 API 문서를 확인 Ext.Array.each에 대한 콜백 첫 번째는 당신이 후있는 데이터를 일부 인수를 취합니다. 그러므로 나는 다음과 같은 것을 원한다고 생각한다.

Ext.Array.each(data.myData, function(data) { 
// Here data contains the data structure sent from your PHP code. 
console.log(data.title); 
console.log(data.message); 
}); 

희망 하시겠습니까?